package com.fs.sw.service.impl;

import com.fs.sw.dao.ConfigRepository;
import com.fs.sw.pojo.ConfigEntity;
import com.fs.sw.service.IConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Optional;

@Service
public class ConfigServiceImpl implements IConfigService {

    @Autowired
    private ConfigRepository configRepository;


    @Transactional
    @Override
    public boolean getFilterCount() {
        Optional<ConfigEntity> optional = configRepository.findById(1);
        if(optional.isPresent()){
            ConfigEntity config = optional.get();
            config.setFiltercount(config.getFiltercount()-1);
            configRepository.save(config);
            return config.getFiltercount()>-1? true:false;
        }else{
            return false;
        }
    }
}
